<%@include file="/WEB-INF/jsp/taglib.jsp" %>
<c:import url="/WEB-INF/jsp/frontend/script.jsp"/>
<c:import url="/WEB-INF/jsp/backend/maintain/head.jsp"/>

<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<div class="super-content RightMain" id="RightMain">

    <!--header-->
    <div class="superCtab">
        <div class="ctab-title clearfix"><h3>文章发布</h3>

            <div class="ctab-Main">


                <div class="ctab-Mian-cont">
                    <div class="Mian-cont-btn clearfix">
                        <div class="operateBtn">
                            <a href="javascript:ShowDiv('Div','mask');" class="greenbtn add sp-add" onclick="modifyRecord(0);">添加帖子</a>
                            <a href="javascript:;" class="modify sp-modify" id="sp-modify">修改</a>
                        </div>
                        <div class="searchBar">
                            <form action="/maintain/postManage" id="searchForm" name="userSearch">
                                <input type="text" value="" class="form-control srhTxt" placeholder="输入标题关键字搜索" id="title_fragment" name="title_fragment">
                                <input type="submit" class="srhBtn" id="postSearchBtn" onclick="submit()" type="submit">
                            </form>
                        </div>
                    </div>


                    <div class="Mian-cont-wrap">
                        <div class="defaultTab-T">
                            <table border="0" cellspacing="0" cellpadding="0" class="defaultTable">
                                <tbody><tr><th class="t_1">帖子标题</th><th class="t_2">帖子内容</th><th class="t_p">帖子作者</th><th class="t_3">发布时间</th><th class="t_4">操作</th></tr>
                                </tbody></table>
                        </div>


                        <table border="0" cellspacing="0" cellpadding="0" class="defaultTable defaultTable2">
                            <tbody>
                            <c:forEach items="${postPage.list}" var="post" varStatus="idx" >
                                <tr>
                                    <td class="t_1" id="post_title${idx.index}">${post.post.postName}</td>

                                    <td class="t_2" id="post_content${idx.index}">${post.postContent.postText}</td>
                                    <td class="t_p" id="post_pub_name${idx.index}">${post.post.postPubName}</td>
                                    <td class="t_3" id="post_date${idx.index}">${post.post.postCreateTime}</td>
                                    <td class="t_4"><div class="btn"><a class="Top">置顶</a><a href="#" class="modify" id="modifybtn${idx.index}" onclick="showPostRecord(${idx.index})">修改</a><a href="#" class="delete">删除</a></div></td>
                                </tr>
                            </c:forEach>

                            </tbody>
                        </table>

                        <div class="pageSelect">
                            <span>共 <b>${postPage.totalRecord}</b> 条 每页 <b>${postPage.pageSize} </b>条   ${postPage.currentPage}/${postPage.totalPage}</span>
                       <%--<span> 页次：${postPage.currentPage}/${postPage.totalPage}&nbsp;每页${postPage.pageSize}&nbsp;总数${postPage.totalRecord}&nbsp;&nbsp;&nbsp;&nbsp;--%>
                        <%--<a href="javaScript:gotoPage(1, '${titleFragment}')" class="pagenumb">首页</a> </span>--%>
                            <div class="pageWrap">
                                <a class="pagePre"><i class="ico-pre">&nbsp;</i></a>



                        <c:choose>
                            <c:when test="${postPage.currentPage>1}">
                                <a href="javaScript:gotoPage('${postPage.currentPage-1}','${titleFragment}')" class="pagenumb">上页</a>
                            </c:when>
                            <c:otherwise>
                                <a href="#" class="pagenumb">上页</a>
                            </c:otherwise>
                        </c:choose>

                        <c:choose>
                            <c:when test="${postPage.currentPage<postPage.totalPage}">
                                <a href="javaScript:gotoPage('${postPage.currentPage+1}','${titleFragment}')" class="pagenumb">下页</a>
                            </c:when>
                            <c:otherwise>
                                <a href="#" class="pagenumb">下页</a>
                            </c:otherwise>
                        </c:choose>
                        <a href="javaScript:gotoPage('${postPage.totalPage}', '${titleFragment}')" class="pagenumb">尾页</a>
                        <select id="userPageSelect" width="50" style="width: 40px" onchange="jumpPage('${titleFragment}');">
                            <c:forEach var="i" begin="1" end="${postPage.totalPage}">

                                <c:choose>
                                    <c:when test="${postPage.currentPage== i}">
                                        <option selected="selected">${i}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option>${i}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                                <a href="#" class="pagenext"><i class="ico-next">&nbsp;</i></a>
                            </div>
                        </div>




                        <%--<div class="pageSelect">--%>

                            <%--<div class="pageWrap">--%>
                                <%--<a class="pagePre"><i class="ico-pre">&nbsp;</i></a>--%>
                                <%--<a href="#" class="pagenumb">首页</a>--%>
                                <%--<a href="#" class="pagenumb">上页</a>--%>
                                <%--<a href="#" class="pagenumb cur">1</a>--%>

                                <%--<a href="#" class="pagenumb">下页</a>--%>
                                <%--<a href="#" class="pagenumb">尾页</a>--%>
                                <%--<a href="#" class="pagenext"><i class="ico-next">&nbsp;</i></a>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <!--pages E-->
                    </div>

                </div>

            </div>
        </div>
        <!--main-->

    </div>
    <!--content E-->

    <div class="layuiBg" id="mask"></div><!--公共遮罩-->
    <!--点击修改弹出层-->


    <div class="addFeileibox layuiBox" style="left: 364px; top: 141px; " id="Div">
        <form name="postModify" id="postForm">
            <div class="layer-title clearfix"><h2>修改帖子信息</h2><span class="layerClose"></span></div>
            <div class="layer-content">

                <div class="aFllink clearfix"><span>标题：</span><input type="text" id="p_title"  name="post_title"/></div>
                <div class="aFllink clearfix"><span>日期：</span><input type="text" id="p_date" name="post_date"/></div>
                <div class="aFllink clearfix"><span>作者：</span><input type="text" id="p_pub_name" name="post_author"/></div>
                <div class="aFllink clearfix"><span>内容：</span><input type="text" id="p_text" name="post_content"/></div>
                <div class="aFllink clearfix"><span>加精：</span><input id="p_Essential" value="true" name="is_essential" type="checkbox"></div>
                <div class="aFlBtn"><input type="button" value="保存" class="saveBtn" onclick="CloseDiv('Div','mask')" id="postModifyBtn" type="submit"></div>
            </div>
        </form>
    </div>





<script>
    var postModifyUrl = "<spring:url value="/maintain/postModify" />";
    var postModifyForm = $("#postForm");
    var postModifyBtn = $("#postModifyBtn");

    postModifyBtn.click(function () {
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: postModifyUrl,
            data: postModifyForm.serialize(),
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    alert(data.msg);
                    location.reload(true);
                } else {
                    alert(data.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("修改失败");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
        return false;
    });


    function deleteConfirm(postId) {
        var conf=confirm("是否删除这篇文章？");
        if(conf == true) {
            postDelete(postId);
        }
    }

    var postDeleteUrl = "<spring:url value="/maintain/postDelete" />";
    function postDelete(postId) {
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: postDeleteUrl,
            data: {"post_id": postId},
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    alert(data.msg);
                    location.reload(true);
                } else {
                    alert(data.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("修改失败");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
        return false;
    }

    function gotoPage(pageNum, titleFragment){
//        console.log();

        var targetURL="<spring:url value='/maintain/postManage?p='/>" + pageNum + "&title_fragment=" + titleFragment;

        document.location.href=targetURL;
    }

    function jumpPage(titleFragment){
        var idx = document.getElementById("userPageSelect").selectedIndex+1;
        var targetURL="<spring:url value='/maintain/postManage?p='/>" + idx + "&title_fragment=" + titleFragment;
        document.location.href=targetURL;

    }


    function ShowDiv(Div,mask)
    {
        document.getElementById(Div).style.display='block';
        document.getElementById(mask).style.display='block';
    }

    function CloseDiv(Div,mask)
    {
        document.getElementById(Div).style.display='none';
        document.getElementById(mask).style.display='none';
    }

</script>
